package com.lych.server.controller;

import com.lych.dubbo.api.CommentVideoApi;
import com.lych.model.vo.PageResult;
import com.lych.server.service.SmallVideoService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideoController {

    @Autowired
    private SmallVideoService smallVideoService;

    /**
     * 视频上传
     * @param videoThumbnail
     * @param videoFile
     * @return
     */
    @PostMapping
    public ResponseEntity smallVideos(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        smallVideoService.smallVideos(videoThumbnail,videoFile);
        return ResponseEntity.ok(null);
    }

    /**
     * 小视频列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping
    public ResponseEntity smallVideos(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = smallVideoService.pageSmallVideos(page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 视频用户关注
     * @param followUserId
     * @return
     */
    @PostMapping("/{uid}/userFocus")
    public ResponseEntity userFocus(@PathVariable("uid") Long followUserId){
        smallVideoService.userFocus(followUserId);
        return ResponseEntity.ok(null);
    }

    /**\
     * 视频用户关注 - 取消
     * @param followUserId
     * @return
     */
    @PostMapping("/{uid}/userUnFocus")
    public ResponseEntity userUnFocus(@PathVariable("uid") Long followUserId) {
        smallVideoService.userUnFocus(followUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 视频点赞
     * @param id
     * @return
     */
    @PostMapping("/{id}/like")
    public ResponseEntity idLike(@PathVariable("id") String id){
        smallVideoService.idLike(id);
        return ResponseEntity.ok(null);
    }

    /**
     * 视频点赞 - 取消
     * @param id
     * @return
     */
    @PostMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String id){
        smallVideoService.dislike(id);
        return ResponseEntity.ok(null);
    }

    /**
     * 评论列表分页查询
     * @param page
     * @param pagesize
     * @param id
     * @return
     */
    @GetMapping("/{id}/comments")
    public ResponseEntity idComments( @RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize,
                                      @PathVariable("id") String id){
        PageResult pr = smallVideoService.idComments(id,page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**\
     * 评论发布
     * @param id
     * @param map
     * @return
     */
    @PostMapping("/{id}/comments")
    public ResponseEntity findComments(@PathVariable("id") String id, @RequestBody Map map){
        //获得视频评论内容
        String comment = (String) map.get("comment");
        smallVideoService.findComments(id,comment);
        return ResponseEntity.ok(null);
    }

    /**
     * 评论点赞
     * @param publishId
     * @return
     */
    @PostMapping("/comments/{id}/like")
    public ResponseEntity commentsIdLike(@PathVariable("id") String publishId){
        smallVideoService.commentsIdLike(publishId);
        return ResponseEntity.ok(null);
    }

    /**
     * 评论点赞 - 取消
     * @param publishId
     * @return
     */
    @PostMapping("/comments/{id}/dislike")
    public ResponseEntity commentsIdDislike(@PathVariable("id") String publishId){
        smallVideoService.commentsIdDislike(publishId);
        return ResponseEntity.ok(null);
    }
}
